package com.atguigu.gmall;

import com.atguigu.gmall.common.constant.RedisConst;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * Springboot启动默认扫描基础包:当前启动类所在包
 * @author: atguigu
 * @create: 2023-06-05 11:56
 */
@SpringBootApplication//(scanBasePackages = {"", "", ""})
@EnableDiscoveryClient //服务注册 服务发现注解
public class ProductApp implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(ProductApp.class, args);
    }

    @Autowired
    private RedissonClient redissonClient;
    /**
     * 初始化布隆过滤器
     * springboot项目启动成功后,执行一次该方法
     * @param args incoming main method arguments
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        //1.获取布隆过滤器对象
        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
        //2.创建设置布隆过滤器数据规模,误判率
        bloomFilter.tryInit(500000, 0.03);
    }

}
